package com.javafactroy.kunlong.test.testservice;

import com.javafactroy.kunlong.DbAgent;
import com.javafactroy.kunlong.base.model.ReturnPageInfo;
import com.javafactroy.kunlong.common.utils.CommonUtils;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import com.javafactroy.kunlong.data.entity.TSysUserApiEntity;
import com.javafactroy.kunlong.data.service.TSysUserService;
import com.github.jsonzou.jmockdata.JMockData;
import com.github.jsonzou.jmockdata.MockConfig;

/**
 * @author raymond.lei@163.com
 * @date 2023-11-11 11:16:50
 */

@SpringBootTest(classes = {DbAgent.class}, webEnvironment = SpringBootTest.WebEnvironment.NONE)
@ExtendWith(SpringExtension.class)
@Slf4j
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(MethodOrderer.MethodName.class)

public class TSysUserTestService {
    @Autowired
    TSysUserService service;

    String pkeyField = "id";

    public TSysUserApiEntity mock() {
        MockConfig mockConfig = new MockConfig()
                .doubleRange(1e-9, 1111222221119999.99999d)
                .floatRange(1e-8f, 111111122221119999.99999f)
                .decimalScale(52).excludes(pkeyField, "orderBys")
                .subConfig("status").intRange(0, 9).globalConfig();
        TSysUserApiEntity entity = JMockData.mock(TSysUserApiEntity.class, mockConfig);
        log.info("mock entity = {}", CommonUtils.toJSONString(entity));
        return entity;
    }


    @Test
    public void test001_query() {

        TSysUserApiEntity sysUserApiEntity = new TSysUserApiEntity();
        sysUserApiEntity.ge("id", 3).setPageSize(4);
        sysUserApiEntity.orderBy("id", "asc");

        ReturnPageInfo<TSysUserApiEntity> param = service.query(sysUserApiEntity);

        log.info("query entity = {}", CommonUtils.toJSONString(param));

    }

    @Test
    public void test002_selectByPkey() {
        TSysUserApiEntity entity = service.selectByPkey(1l);
        log.info("selectByPkey entity = {}", entity);

    }

    @Test
    public void test003_save() {

        TSysUserApiEntity entity = mock();
        service.save(entity);

        log.info("save entity = {}", entity);

    }
}

